<?php
namespace app\common\exception;

use Exception;
use think\exception\Handle;
use think\Config;
use think\Log;

// 自定义异常类 主要为解决部署模式下 不显示详细错误(文件和行号)信息而扩展
class Myhandle extends Handle
{

    public function report(Exception $exception)
    {
        if (!$this->isIgnoreReport($exception)) {
            // 收集异常数据
            
                $data = [
                    'file'    => $exception->getFile(),
                    'line'    => $exception->getLine(),
                    'code'    => $this->getCode($exception),
                    'message' => $this->getMessage($exception),
                ];
                $log = "[{$data['code']}]{$data['message']}[{$data['file']}:{$data['line']}]";

            if (Config::get('record_trace')) {
                $log .= "\r\n" . $exception->getTraceAsString();
            }

            Log::record($log, 'error');
        }
    }
}
